package org.ddr.member.dao;

import java.util.ArrayList;
import java.util.List;

import org.ddr.member.MemberVO;

public class MemberDAOImpl implements MemberDAO {

	private static final MemberDAOImpl instance;

	static {
		instance = new MemberDAOImpl();
	}

	private MemberDAOImpl() {
		;
	}

	public static MemberDAOImpl getInstance() {
		return instance;
	}

	@Override
	public List<MemberVO> getUser(final String userId, final String pw) throws Exception {

		final List<MemberVO> list = new ArrayList<MemberVO>();
		new MemAbstractExecutor() {

			@Override
			protected void execute() throws Exception {
				StringBuffer sql = new StringBuffer();
				sql.append(" SELECT * ");
				sql.append(" FROM TBL_MEMBER ");
				sql.append(" WHERE userid = ? AND pw = ? ");
				
				pstmt = con.prepareStatement(sql.toString());
				pstmt.setString(1, userId);
				pstmt.setString(2, pw);
				
				rs = pstmt.executeQuery();

				rs.next();

				list.add(new MemberVO(rs.getString(1), rs.getString(2), rs
						.getString(3), rs.getInt(4), rs.getString(5)));

			}
		}.doJob();
		return list;
	}

	@Override
	public void update(MemberVO vo) throws Exception {
		
		new MemAbstractExecutor() {
			
			@Override
			protected void execute() throws Exception {
				
			}
		}.doJob();
		
	}

	@Override
	public void registUser(final MemberVO vo) throws Exception {
		
		new MemAbstractExecutor() {
			
			@Override
			protected void execute() throws Exception {
				
				StringBuffer sql = new StringBuffer();
				sql.append(" INSERT INTO TBL_MEMBER(userid, name, sex, age, pw) ");
				sql.append(" VALUES (?, ?, ?, ?, ?) ");
				pstmt = con.prepareStatement(sql.toString());
				pstmt.setString(1, vo.getUserid());
				pstmt.setString(2, vo.getName());
				pstmt.setString(3, vo.getSex());
				pstmt.setInt(4, vo.getAge());
				pstmt.setString(5, vo.getPw());
				
				rs = pstmt.executeQuery();
			}
		}.doJob();
	}

}
